#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
//
//class Stack
//{
//public:
//	Stack(int capacity = 4)
//	{
//		cout << "Stack(int capacity = 4)" << endl;
//
//		_a = new int[capacity];
//		_top = 0;
//		_capacity = capacity;
//	}
//
//	~Stack()
//	{
//		cout << "~Stack()" << endl;
//
//		delete[] _a;
//		_a = nullptr;
//		_top = 0;
//		_capacity = 0;
//	}
//private:
//	int* _a;
//	int  _top;
//	int  _capacity;
//};

//int main()
//{
//	Stack* p1 = new Stack;
//	Stack* p2 = new Stack[5];
//
//	Stack* p3 = (Stack*)operator new(sizeof(Stack));
//	Stack* p4 = (Stack*)malloc(sizeof(Stack));
//
//	new(p3)Stack;
//	new(p4)Stack;
//	p3->~Stack();
//	p4->~Stack();
//
//	delete p1;
//	delete[] p2;
//	delete p3;
//	delete p4;
//	free(p4);
//	return 0;
//}

class A
{
public:
	A(int a = 0)
		: _a(a)
	{
		cout << "A():" << this << endl;
	}

	//~A()
	//{
	//	cout << "~A():" << this << endl;
	//}

private:
	int _a;
};

//int main()
//{
//	//A* a1 = (A*)malloc(sizeof(A));
//
//	A* a2 = new A[5];
//	//delete a2;
//	free(a2);
//	return 0;
//}

//template<class T>
//void Swap(T& m, T& n)
//{
//	T k = m;
//	m = n;
//	n = k;
//}
//

//
////template<class T1,class T2>
////T1 sum(T1& a, T2& b)
////{
////	return a + b;
////}
////
////template<class T1, class T2>
////T2 sum(T1& a, T2& b)
////{
////	return a + b;
////}

template<class T>
//T sum(T& a, T b)
//{
//	return a + b;
//}
T sum(const T& a, const T& b)
{
	return a + b;
}
//
//int main()
//{
//	int a = 1, b = 2;
//	double c = 1.1, d = 2.2;
//	cout << "a=" << a << "  " << "b=" << b << endl;
//	cout << "c=" << c << "  " << "d=" << d << endl;
//
//	/*Swap(a, b);
//	cout << "a=" << a << "  " << "b=" << b << endl;
//
//	Swap(c, d);
//	cout << "c=" << c << "  " << "d=" << d << endl;*/
//
//	int sum1 = sum(a, b);
//	int sum2 = sum(c, d);
//	int sum3 = sum(a, (int)c);
//	double sum4 = sum<double>(b, d);
//	cout << sum1 << "  " << sum2 << "  " << sum3 << "  " << sum4 << endl;
//	//cout << sum1 << "  " << sum2 << "  " << endl;
//	//cout << sum3 << "  " << sum4 << endl;
//	//cout << sum3 << "  " << endl;
//	//cout << sum4 << "  " << endl;
//}
//
//template<class T>
////T Add(T& left, T& right)
//T Add(T left, T right)
//{
//	return left + right;
//}
//
//template<class T>
//T* f(int n)
//{
//	T* p = new T[n];
//	return p;
//}
//
//int main()
//{
//
//	cout << Add(1, (int)2.2) << endl;
//
//	cout << Add<int>(1, 2.2) << endl;
//	cout << Add<double> (1, 2.2) << endl;
//
//	double* p = f<double>(10);
//
//	return 0;
//}

template<class T>
class Stack
{
public:
	Stack(int capacity = 4)
	{
		cout << "Stack(int capacity = 4)" << endl;

		_a = new T[capacity];
		_top = 0;
		_capacity = capacity;
	}

	~Stack()
	{
		cout << "~Stack()" << endl;

		delete[] _a;
		_a = nullptr;
		_top = 0;
		_capacity = 0;
	}
private:
	T* _a;
	int  _top;
	int  _capacity;
};
int main()
{
	Stack<int> s1[5];
	Stack<double> s2[5];

	s1[0].~Stack();

	s2[0].~Stack();
	return 0;
}